﻿using ApplicationBase.Core.Domain;
using IdentityService.Domain.Aggregates.UserAccountAggregate;

namespace IdentityService.Domain.Aggregates.RoleAggregate
{
    public class Role : Entity
    {
        public long Id { get; init; }
        public string Name { get; private set; }
        public string Description { get; private set; }
        public string AppName { get; private set; }
        public List<UserAccount> UserAccounts { get; private set; } = new();
        public List<RolePermit> Permits { get; set; } = new();
        //public List<RoleClaim> Claims { get; private set; } = new();

        public Role(long id, string name, string appName, string description = "")
            => (Id, Name, Description, AppName) = (id, name, description, appName);

        public void AddUserAccountRange(List<UserAccount> accounts)
            => UserAccounts = UserAccounts.Union(accounts).ToList();

        public void RemoveUserAccountRange(List<UserAccount> accounts)
        {
            var intersectList = UserAccounts.Intersect(accounts).ToList();
            UserAccounts = UserAccounts.Except(intersectList).ToList();
        }

        public void Modify(string name, string description)
            => (Name, Description) = (name, description);

        //public List<RolePermit> DeleteAbsentPermits(List<RolePermit> permits)
        //{
        //    var union = Permits.Union(permits).ToList();
        //    return 
        //}

        //public List<RolePermit> FindNeedAddPermits(List<RolePermit> permits)
        //{
        //    var union = Permits.Union(permits).ToList();
        //    return permits.Except(union).ToList();
        //}
    }
}
